<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    
    li {
float:left;
list-style: none;
}
 li img{
    width: 150px;
    height: 150px;
    margin: 100px auto;
}
</style>

<body>
    <ul>
       <li><img src="1.jpg"></li>
       <li><img  src="2.jpg"></li>
       <li><img src="3.jpg"></li>
       <li><img src="4.jpg"></li>
    
    </ul>
    <script>
        var img=document.querySelector("ul").querySelectorAll("img");
        for(var i=0;i<img.length;i++){       
       img[i].onclick=function(){
        document.body.style.backgroundImage="url("+this.src+")";
       }}
    </script>
</body>
</html>